home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_mc.idb / usr / freeware / lib / mc / extfs / a.z / a
Encoding:
Text File  |  1998-10-28  |  1.8 KB  |  83 lines

  1. #! /usr/bin/perl
  2. #
  3. # External filesystem for mc, using mtools
  4. # Written Ludek Brukner (lubr@barco.cz), 1997
  5. #
  6. # WARNING - This software is ALPHA - Absolutely NO WARRANTY
  7.  
  8. ### Change this when the commands are outside PATH
  9. $mdir = "mdir";
  10. $mcopy = "mcopy";
  11. ###
  12.  
  13. $disk = $0;
  14. $disk =~ s/^.*\/([^\/]*)$/\1/;
  15.  
  16. sub get_dirs {
  17.     my ($path, $name, $size, $date, $time, $longname, @lst, @rv);
  18.  
  19.     $path = shift(@_);
  20.     @rv = ();
  21.  
  22.     open(FILE,"$mdir $disk:/$path |");
  23.     while ( <FILE> ) {
  24.     chomp();
  25.     /^ / && next;                            # ignore `non-file' lines
  26.     /^$/ && next;                            # ignore empty lines
  27.     /^\.\.?/ && next;                        # ignore `.' and `..'
  28.  
  29.     $name = substr($_,0,12);
  30.     $name =~ s/^([^ ]*) +([^ ]+)[ \t]*$/$1.$2/;
  31.     $name =~ s/[ .]+$//;
  32.  
  33.     $_ = substr($_,12);
  34.     s/^[ ]+//;
  35.  
  36.     ($size,$date,$time,$longname) = split(/[ \t]+/);
  37.  
  38.         @lst = split(/([:ap])/, $time);
  39.         $lst[0] += 12 if ($lst[3] eq "p");
  40.     $time = sprintf("%02d:%02d", $lst[0], $lst[2]);
  41.     @lst = split(/-/, $date);
  42.     $lst[2] %= 100 if ($lst[2] > 100);
  43.     $date = sprintf ("%02d-%02d-%02d", @lst);
  44.  
  45.     $name = $path . lc(($longname) ? $longname : $name);
  46.  
  47.     if ($size =~ /DIR/) {
  48.         printf("drwxr-xr-x   1 %-8d %-8d %8d %s %s %s\n", 0, 0, 0, $date, $time, $name);
  49.        push @rv, $name;
  50.     }
  51.     else {
  52.         printf("-rw-r--r--   1 %-8d %-8d %8d %s %s %s\n", 0, 0, $size, $date, $time, $name);
  53.     }
  54.     }
  55.     close(FILE);
  56.     return @rv;
  57. }
  58.  
  59. sub a_list
  60. {
  61.     my (@files, $file);
  62.  
  63.     @files = get_dirs("");
  64.     while ($file = shift(@files)) {
  65.         push @files, get_dirs("$file/");
  66.     }
  67. }
  68.  
  69. sub a_copyout
  70. {
  71.     my($archname,$filename,$dest) = @_;
  72.     system "$mcopy $disk:/$filename $dest";
  73. }
  74.  
  75. #    system "touch /tmp/deb";
  76.  
  77. if($ARGV[0] eq "list") { shift; &a_list(@ARGV); exit 0; }
  78. elsif($ARGV[0] eq "copyout") { shift; &a_copyout(@ARGV); exit 0; }
  79.  
  80. exit 1;
  81.  
  82.